# @Time : 2020/7/30 14:45
# @Author : Fioman 
# @Phone : 13149920693
"""
center,radius = cv.minEnclosingCircle(points)
"""
import cv2 as cv
import numpy as np

img = cv.imread("cc.bmp")
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow("Original", img)

T, thres = cv.threshold(gray, 127, 255, cv.THRESH_BINARY)
cv.imshow("Thres", thres)
image, contours, hierarchy = cv.findContours(thres, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE)

center, radius = cv.minEnclosingCircle(contours[0])
center = (int(center[0]), int(center[1]))
radius = int(radius)
print("center = {},radius = {}".format(center, radius))

cv.circle(img, center, radius, (0, 255, 0), thickness=1)
cv.imshow("MinEnclosingCircle", img)
cv.waitKey(0)
